package DataModel.LayoutManager;

import java.awt.Point;

public class CEdge implements Comparable
{
	/***************************************************/
	/****** C'tors *************************************/
	/***************************************************/
	public CEdge(int startX, int startY, int endX, int endY, long ID, CRectangle owner) 
	{
		setStartPoint(new Point(startX,startY));
		setEndPoint(new Point(endX,endY));
		
		setID(ID);
		setOwnerRec(owner);
	}
	
	
	/***************************************************/
	/****** Members ************************************/
	/***************************************************/
	private Point m_startPoint;
	private Point m_endPoint;
	
	private long m_id;
	
	private CRectangle m_ownerRec;
	
	
	/***************************************************/
	/****** Getters / Setters **************************/
	/***************************************************/
	public long getID() {
		return m_id;
	}
	public void setID(long m_id) {
		this.m_id = m_id;
	}
	public CRectangle getOwnerRec() {
		return m_ownerRec;
	}
	public void setOwnerRec(CRectangle rec) {
		m_ownerRec = rec;
	}
	public Point getStartPoint() {
		return m_startPoint;
	}
	public void setStartPoint(Point point) {
		m_startPoint = point;
	}
	public Point getEndPoint() {
		return m_endPoint;
	}
	public void setEndPoint(Point point) {
		m_endPoint = point;
	}
	
	/***************************************************/
	/****** Public Methods **************************/
	/***************************************************/
	public long GetLength()
	{
		return (long) Math.sqrt(
			Math.pow(m_startPoint.x - m_endPoint.x, 2) 
			+ 
			Math.pow(m_startPoint.y - m_endPoint.y, 2));
	}
	
	public String ToString()
	{
		String edgeStr = new String();
		
		edgeStr = getStartPoint().x + " " + getStartPoint().y + " , " + 
					getEndPoint().x + " " + getEndPoint().y;		
		
		return edgeStr;
	}
	/**
	 * cheks if two edges have same coords and direction in space\
	 * @param e - edge to compare to 
	 * @return true if edges are equal in coordinates and direction.
	 */
	
	public static  boolean CompareCoords(CEdge e1, CEdge e2) {
		boolean c1= (e1.getStartPoint().x==e2.getStartPoint().x);
		boolean c2= (e1.getStartPoint().y==e2.getStartPoint().y);
		boolean c3= (e1.getEndPoint().x == e2.getEndPoint().x);
		boolean c4= (e1.getEndPoint().y == e2.getEndPoint().y);
		return (c1&&c2&&c3&&c4);	
	}
	/**
	 * Comparator in order to sort the edges,(X,Y)
	 */
	public int compareTo(Object arg0) {
		CEdge e = (CEdge) arg0;
		if (this.getStartPoint().x < e.getStartPoint().x )
			return -1;
		else if (this.getStartPoint().x > e.getStartPoint().x )
			return 1;
		else if (this.getStartPoint().y < e.getStartPoint().y)
			return -1;
		else if (this.getStartPoint().y > e.getStartPoint().y)
			return 1;
		
		return 0;
	}
	
	public static void printEdge(CEdge e) {
		System.out.println("["+e.getStartPoint().x+","+e.getStartPoint().y+":"+e.getEndPoint().x+","+e.getEndPoint().y+"]");
	}

}
